

var Ajax = {

  _RET_NULL   : " ",
  _CONN_ERROR : "****",
  
  /**
	* set serial number based on srcObject number and dstObject
	*
	* @param  string  srcStart
	* @param  String  srcLength
	* @param  string  srcObject
	* @param  String  dstObject
	*
	*/
	setSerNumber : function (srcStart, 
		                       srcLength,
		                       srcObject, 
		                       dstObject){
	
	  var _STOP       = false; 
	  var _RET_NULL   = " ";
	  var _NO_NUMBER  = "_NO_NUMBER";
	  
	  var stsContinue = true;
	
	  srcStart  = document.getElementsByName(srcStart);
	  srcLength = document.getElementsByName(srcLength);
	  srcObject = document.getElementsByName(srcObject);
	  dstObject = document.getElementsByName(dstObject);
	  
	  srcStart  = GMisc.firstElement(srcStart);
	  srcLength = GMisc.firstElement(srcLength);
	  srcObject = GMisc.firstElement(srcObject);
	  dstObject = GMisc.firstElement(dstObject);
	  
	  /**
	  * Make sure everything is not empty
	  * 
	  */
	  if(dstObject.value != ""){
	    
	    if(srcStart.value == ""){
	      
	      stsContinue = _STOP;
	    }
	    
	    if(srcLength.value == ""){
	      
	      stsContinue = _STOP;
	    }
	  }
	  
	  if(stsContinue == true){
	    
	    var xmlHttp = new XMLHttpRequest();
	    
	    var url     = "/ecs/tocmenu_43/controllers/getSerNumber.php" + "?sid="+Math.random();
	    
	    var params  = "srcStart="      + srcStart.value   +
	                  "&srcLength="    + srcLength.value  +
	                  "&srcTotal="     + srcObject.value  +
	                  "&srcSerNumber=" + dstObject.value  ;
	                  
	    xmlHttp.open("POST", url, false);
	    
	    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
	    xmlHttp.setRequestHeader("Content-length", params.length);
	    xmlHttp.setRequestHeader("Connection", "close");
	    
	    xmlHttp.onreadystatechange = function() {//Call a function when the state changes.
	      
	    }
	    
	    xmlHttp.send(params);
	    
	    switch(xmlHttp.responseText){
            
        case _RET_NULL:
          
          alert("Error: System has given up, calculation failed");
          break;
        
        case _NO_NUMBER:
        
          /* Do nothing */
          break;
                
        default:
        
          dstObject.value = xmlHttp.responseText;
      }
	  }
	},
  
  model : function(isAll, thisObj){
  
    var xmlHttp = new XMLHttpRequest();
    
    var url     = "/ecs/tocmenu_12/controllers/getModel.php" +"?sid="+Math.random();
    var params  = "isAll=" + isAll;
    
    xmlHttp.open("POST", url, false);
    
    xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xmlHttp.setRequestHeader("Content-length", params.length);
    xmlHttp.setRequestHeader("Connection", "close");
    
    xmlHttp.onreadystatechange = function() {
      
    }
    
    xmlHttp.send(params);
    
    switch(xmlHttp.responseText){
      
      case this._CONN_ERROR:
      
        alert("Db Connection failed");
        break;
        
      case this._RET_NULL:
      
        alert("System has given up");
        break;
      
      default:
        thisObj.innerHTML = xmlHttp.responseText;
    }
  },

  sayHello : function(){
  
    alert("Ajax Linked");
  }
} 